import pandas as pd
import matplotlib.pyplot as plt

import pandas as pd
import matplotlib.pyplot as plt

title_fontsize=20
label_fontsize=16
legend_fontsize=14


def plot_from_excel(file_path, plot_details):
    # 打印所有可用的样式
    print("可用的样式:", plt.style.available)

    # 设置绘图样式，您可以从打印的列表中选择一个样式，这里我选择 'seaborn'
    plt.style.use('seaborn-v0_8')

    # 读取 Excel 文件
    data = pd.read_excel(file_path)

    # 设置绘图布局
    fig, axes = plt.subplots(1, 2, figsize=(16, 6))  # 1行2列的图表布局，总体大小为12x6英寸

    # 遍历每个 plot_detail 并在对应的轴上绘图
    for ax, details in zip(axes, plot_details):
        for y_col, label in zip(details['y_cols'], details['labels']):
            ax.plot(data[details['x_col']], data[y_col], label=label)

        # 设置单个图的标题和轴标签
        ax.set_title(details['title'], fontsize=title_fontsize)
        ax.set_xlabel(details['xlabel'], fontsize=label_fontsize)
        ax.set_ylabel(details['ylabel'], fontsize=label_fontsize)

        # 显示图例
        ax.legend(fontsize=legend_fontsize)

    # 调整布局
    plt.tight_layout()

    plt.subplots_adjust(wspace=0.3)

    # 显示图像
    plt.show()


# plot_from_excel(
#     file_path=r"C:\Users\xendx\Desktop\models\lab1.xlsx",
#     plot_details=[
#         {
#             'x_col': 'epoch',
#             'y_cols': ['loss_mfcc', 'loss_fbank'],
#             'labels': ['MFCC', 'Fbank'],
#             'title': 'loss',
#             'xlabel': 'epoch',
#             'ylabel': 'loss'
#         },
#         {
#             'x_col': 'epoch',
#             'y_cols': ['acc_mfcc', 'acc_fbank'],
#             'labels': ['MFCC', 'Fbank'],
#             'title': 'acc',
#             'xlabel': 'epoch',
#             'ylabel': 'acc'
#         }
#     ]
# )

# plot_from_excel(
#     file_path=r"C:\Users\xendx\Desktop\models\lab2.xlsx",
#     plot_details=[
#         {
#             'x_col': 'epoch',
#             'y_cols': ['loss_18', 'loss_34', 'loss_50'],
#             'labels': ['ResNet18', 'ResNet34', 'ResNet50'],
#             'title': 'loss',
#             'xlabel': 'epoch',
#             'ylabel': 'loss'
#         },
#         {
#             'x_col': 'epoch',
#             'y_cols': ['acc_18', 'acc_34', 'acc_50'],
#             'labels': ['ResNet18', 'ResNet34', 'ResNet50'],
#             'title': 'acc',
#             'xlabel': 'epoch',
#             'ylabel': 'acc'
#         }
#     ]
# )

# plot_from_excel(
#     file_path=r"C:\Users\xendx\Desktop\models\lab3.xlsx",
#     plot_details=[
#         {
#             'x_col': 'epoch',
#             'y_cols': ['loss_r18', 'loss_r34', 'loss_c18', 'loss_c34'],
#             'labels': ['ResNet18', 'ResNet34', 'CNN18', 'CNN34'],
#             'title': 'loss',
#             'xlabel': 'epoch',
#             'ylabel': 'loss'
#         },
#         {
#             'x_col': 'epoch',
#             'y_cols': ['acc_r18', 'acc_r34', 'acc_c18', 'acc_c34'],
#             'labels': ['ResNet18', 'ResNet34', 'CNN18', 'CNN34'],
#             'title': 'acc',
#             'xlabel': 'epoch',
#             'ylabel': 'acc'
#         }
#     ]
# )

# plot_from_excel(
#     file_path=r"C:\Users\xendx\Desktop\models\lab4.xlsx",
#     plot_details=[
#         {
#             'x_col': 'epoch',
#             'y_cols': ['loss_34', 'loss_50', 'loss_34e', 'loss_50e'],
#             'labels': ['ResNet34', 'ResNet50', 'exq-ResNet34', 'exq-ResNet50'],
#             'title': 'loss',
#             'xlabel': 'epoch',
#             'ylabel': 'loss'
#         },
#         {
#             'x_col': 'epoch',
#             'y_cols': ['acc_34', 'acc_50', 'acc_34e', 'acc_50e'],
#             'labels': ['ResNet34', 'ResNet50', 'exq-ResNet34', 'exq-ResNet50'],
#             'title': 'acc',
#             'xlabel': 'epoch',
#             'ylabel': 'acc'
#         }
#     ]
# )

plot_from_excel(
    file_path=r"C:\Users\xendx\Desktop\models\lab5.xlsx",
    plot_details=[
        {
            'x_col': 'epoch',
            'y_cols': ['loss_128', 'loss_256', 'loss_512', 'loss_1024'],
            'labels': ['128', '256', '512', '1024'],
            'title': 'loss',
            'xlabel': 'epoch',
            'ylabel': 'loss'
        },
        {
            'x_col': 'epoch',
            'y_cols': ['err_128', 'err_256', 'err_512', 'err_1024'],
            'labels': ['128', '256', '512', '1024'],
            'title': 'ERR',
            'xlabel': 'epoch',
            'ylabel': 'ERR'
        }
    ]
)